package com.zwjstudy.ehcache2;

import com.zwjstudy.ehcache2.entity.Dog;
import net.sf.ehcache.Cache;
import net.sf.ehcache.CacheManager;
import net.sf.ehcache.Element;

/**
 * ClassName: Ehcache2Test2
 * Package: com.zwjstudy.ehcache2
 * Description:
 *
 * @Author: 张文俊
 * @Create: 2025-09-17 - 10:56
 * @Version: v1.0
 */
public class Ehcache2Test2 {

    public static void main(String[] args) {
        //1.创建CacheManager
//        CacheManager cacheManager = CacheManager.create("./src/main/resources/ehcache.xml");
        //默认就是在类路径的ehcache.xml
//        CacheManager cacheManager=CacheManager.create();
        CacheManager cacheManager = CacheManager.newInstance();
        //2.获取cache实例
        Cache helloWorldCache = cacheManager.getCache("HelloWorldCache");

        //3.存入数据
        Dog dog = new Dog("小黑","黑色",2);
        Element element = new Element("dog",dog);
        helloWorldCache.put(element);

        //4.获取缓存数据

        Element value = helloWorldCache.get("dog");
        Dog objectValue = (Dog)value.getObjectValue();
        System.out.println("value="+value);
        System.out.println("objectValue = " + objectValue);

        //5.关闭CacheManager
        cacheManager.shutdown();
    }
}
